package com.studio.framework.controller.monitorSystem.service;

import com.studio.framework.controller.monitorSystem.bean.ErrorLog;
import com.studio.framework.controller.monitorSystem.dto.ErrorLogDto;
import com.studio.framework.controller.monitorSystem.repository.ErrorLogRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author jujh
 * @Date 2018/7/23
 * 错误日志
 */
@Service
public class ErrorLogService {

    @Autowired
    private ErrorLogRepository errorLogRepository;


    /**
     * 条件查询所有
     *
     * @return
     */
    public List<ErrorLog> findAllByCondition(ErrorLogDto errorLogDto) {
        Sort sort = new Sort(Sort.Direction.DESC, "createDate");
        ErrorLog errorLog = new ErrorLog();
        Example<ErrorLog> example = Example.of(errorLog);
        if (errorLogDto.getGroupName() != null && !"".equals(errorLog.getGroupName())) {
            errorLog.setGroupName(errorLogDto.getGroupName());
        }
        return errorLogRepository.findAll(example, sort);
    }

    /**
     * add
     *
     * @return
     */
    public String create(ErrorLog errorLog) {
        errorLog = errorLogRepository.save(errorLog);
        return errorLog.getId();
    }

    /**
     * 查询详情
     *
     * @return
     */
    public String findById() {
        return null;
    }

    /**
     * update
     *
     * @return
     */
    public String update() {
        return null;
    }


}
